﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO;

namespace DAO
{

	public class UsersDAO:IData<Users> 
 	{
		public UsersDAO(String myconnecString) : base(myconnecString) { }

		public override int OnSubmit(Users item, int t) {
			 return connec.ExecuteNonQuery("sp_Users", CommandType.StoredProcedure,new SqlParameter("@flag", t),
				 new SqlParameter("@" + Users.c_id, item.id), new SqlParameter("@" + Users.c_userName, item.userName),
				 new SqlParameter("@" + Users.c_fullName, item.fullName), new SqlParameter("@" + Users.c_password, item.password),
				 new SqlParameter("@" + Users.c_email, item.email), new SqlParameter("@" + Users.c_create_on, item.create_on),
				 new SqlParameter("@" + Users.c_groupID, item.groupID), new SqlParameter("@" + Users.c_lastDate, item.lastDate),
				 new SqlParameter("@" + Users.c_status, item.status), new SqlParameter("@" + Users.c_passDate, item.passDate),
				 new SqlParameter("@" + Users.c_address, item.address), new SqlParameter("@" + Users.c_phone, item.phone),
				 new SqlParameter("@" + Users.c_isActive, item.isActive)); 
		}

		public override Users GetItem(IDataReader dr)
		{
			Users obj = new Users();
			obj.id = Convert.ToInt64(dr[Users.c_id]);
			obj.userName = Convert.ToString(dr[Users.c_userName]);
			obj.fullName = Convert.ToString(dr[Users.c_fullName]);
			obj.password = Convert.ToString(dr[Users.c_password]);
			obj.email = Convert.ToString(dr[Users.c_email]);
			obj.create_on = Convert.ToDateTime(dr[Users.c_create_on]);
			obj.groupID = Convert.ToInt32(dr[Users.c_groupID]);
			obj.lastDate = Convert.ToDateTime(dr[Users.c_lastDate]);
			obj.status = Convert.ToInt32(dr[Users.c_status]);
			obj.passDate = Convert.ToDateTime(dr[Users.c_passDate]);
			obj.address = Convert.ToString(dr[Users.c_address]);
			obj.phone = Convert.ToString(dr[Users.c_phone]);
			obj.isActive = Convert.ToInt32(dr[Users.c_isActive]);
			return obj;
		}

		public override List<Users> GetAll()
		{
			return GetAll("select * from " + Users.b_Users, CommandType.Text);
		}

		public override Users GetItemById(object id)
		{
			throw new NotImplementedException();
		}

	}

 }
